package array

func Find[T any](array []T, predicate func(T) bool) (T, bool) {
	var zero T
	for _, v := range array {
		if predicate(v) {
			return v, true
		}
	}
	return zero, false
}

func FindIndex[T any](array []T, predicate func(T) bool) (int, bool) {
	for i, v := range array {
		if predicate(v) {
			return i, true
		}
	}
	return -1, false
}

func FindLast[T any](array []T, predicate func(T) bool) (T, bool) {
	var zero T
	for i := len(array) - 1; i >= 0; i-- {
		if predicate(array[i]) {
			return array[i], true
		}
	}
	return zero, false
}

func FindLastIndex[T any](array []T, predicate func(T) bool) (int, bool) {
	for i := len(array) - 1; i >= 0; i-- {
		if predicate(array[i]) {
			return i, true
		}
	}
	return -1, false
}

func IndexOf[T comparable](array []T, element T) int {
	for i, v := range array {
		if v == element {
			return i
		}
	}
	return -1
}

func Includes[T comparable](array []T, element T) bool {
	for _, v := range array {
		if v == element {
			return true
		}
	}
	return false
}

func LastIndexOf[T comparable](array []T, element T) int {
	for i := len(array) - 1; i >= 0; i-- {
		if array[i] == element {
			return i
		}
	}
	return -1
}
